package pro.softzhang.algo.lc900;

import pro.softzhang.algo.flag.theme.TDesign;

import java.util.LinkedList;
import java.util.Queue;

/**
 *
 */
@TDesign
public class LC933_NumberOfRecentCalls {

    public static void main(String[] args) {
        RecentCounter rc = new RecentCounter();
        System.out.println(rc.ping(1));
        System.out.println(rc.ping(100));
        System.out.println(rc.ping(3001));
        System.out.println(rc.ping(3002));
    }

    /**
     * 
     */
    static
    class RecentCounter {
        private Queue<Integer> queue;
        private int windowSize;

        public RecentCounter() {
            queue = new LinkedList<>();
            windowSize = 3000;
        }

        public int ping(int t) {
            queue.offer(t);
            while (queue.peek() + windowSize < t) {
                queue.poll();
            }
            return queue.size();
        }
    }
}